// ignore_for_file: prefer_const_constructors, avoid_unnecessary_containers, prefer_const_literals_to_create_immutables, unused_local_variable, sized_box_for_whitespace
import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety_flutter3/flutter_swiper_null_safety_flutter3.dart';
import 'package:rabbit/models/home_models.dart';
import 'package:rabbit/services/home_api.dart';

import 'widgets/image_swipe_widget.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  //轮播图数据
  List<ImageBannersModel>? imageBanners;

  // 获取首页数据
  loadData() async {
    HomeModel homeModel = await HomeAPI.homeFetch();

    setState(() {
      imageBanners = homeModel.imageBanners;
    });
  }

  @override
  void initState() {
    loadData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('首页'),
        backgroundColor: Color.fromARGB(255, 105, 105, 210),
      ),
      body: CustomScrollView(
        slivers: [
          //轮播图
          SliverToBoxAdapter(
              child: Padding(
                  // 设置内边距
                  padding: EdgeInsets.only(
                    left: 10,
                    top: 10,
                    right: 10,
                  ),
                  child: ImageSwiperWidget(
                    imageBanners: imageBanners,
                    height: 140.0,
                  )))
        ],
      ),
    );
  }
}
